package org.JQbitorrentClinet;

import org.JQbitorrentClinet.impl.base.ApiVersionGetter;
import org.JQbitorrentClinet.impl.V283.Client_V2_8_3;
import org.JQbitorrentClinet.interfaces.Client;
import org.JQbitorrentClinet.utils.InternalHttpClient;

public class ClientFactory {
    private static InternalHttpClient httpClient = new InternalHttpClient();

    public static Client createClient(String host, int port, String username, String password) {
        return createClient(host, port, username, password, "http");
    }

    public static Client createHTTPSClient(String host, int port, String username, String password) {
        return createClient(host, port, username, password, "https");
    }

    private static Client createClient(String host, int port, String username, String password, String protocol) {
        QBitorrentConnectionInfo connectionInfo = new QBitorrentConnectionInfo(host, port, username, password, protocol, httpClient);
        ApiVersionGetter apiVersionGetter = new ApiVersionGetter(connectionInfo);
        String apiVersion = apiVersionGetter.getApiVersion();
        switch (apiVersion) {
            case "2.8.3":
                return new Client_V2_8_3(connectionInfo);
            default:
                throw new RuntimeException("Unsupported API version: " + apiVersion);
        }
    }
}
